import axios from 'axios'

axios.interceptors.request.use(config => {
    // 检查请求是否是登录接口，如果是，则不携带 token
    if (config.isLoginRequest) {
        return config;
    } else {
        const storedDataString = localStorage.getItem('apiData');
        if (storedDataString) {
            const storedData = JSON.parse(storedDataString);
            if (storedData && storedData.token) {
                config.headers.token = storedData.token;
            }
        }
        return config;
    }


}, err => {
    return Promise.reject(err);
});

// 定义响应拦截器
axios.interceptors.response.use(function (response) {
    if (response.data.code == '401') {
        // localStorage.removeItem('apiData');
        // window.location.reload()
    }
    return response
}, function (error) {
    return Promise.reject(error)

})
export default axios